package com.Model.cunqv;

import com.sql.DAO;

import com.Model.Date.DateTime;
import com.Model.Pojo.Users;

public class CunKuanQvKuan {
	
	public void cunQv(String name, String type, int num){ //还没写好哦还不能用
		int cunmoney = num;
		String style;
		String style1;
		String source; //来源备注信息
    	if(type.equals("f1")){
    		style = "1";
    		style1 = "存款";
    		source = "存入余额";
    	}else{
    		cunmoney *= -1;
    		style = "0";
    		style1 = "取款";
    		source = "余额取出";
    	}
		
    	Users usermoney = new Users();
    	
		
		int money = usermoney.getYue();//获取用户的账户余额
		int cash = usermoney.getMoney();//获取用户的现金
		money += cunmoney;
		cash -= cunmoney;
		DAO dao = new DAO();
		String usersname = usermoney.getZhanghao();
		String sql = "update users set yue='" + money + "' where name='" + usersname + "' ";
		dao.xiugai(sql);//更新users表中用户的账户余额
		sql = "update users set money='" + cash + "' where name='" + usersname + "' ";
		dao.xiugai(sql);//更新users表中用户的现金
		
		if(style.equals("0")){//如果是取钱的话
			cunmoney *= -1;
		}
		DateTime date = new DateTime();
		sql = "insert into cunkuanqvkuan (name,money,style,date,yue)value('" + usersname + "','" + cunmoney 
						+ "','" + style + "','" + date.getSettime() + "','" + money + "')";
		dao.zengjia(sql);
		
		sql = "insert into moneylist (name,style,value,date,cash,source)value('" + usersname + "','" + style1
		+ "','" + cunmoney + "','" + date.getSettime() + "','" + cash + "','" + source + "')";
		dao.zengjia(sql);
	}
}
